package cn.element.netty.future;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;

@Slf4j
public class TestNettyFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        NioEventLoopGroup group = new NioEventLoopGroup();
        EventLoop loop = group.next();
        Future<Integer> future = loop.submit(() -> {
            log.debug("执行计算...");
            Thread.sleep(1000);
            return 100;
        });
        
//        log.debug("等待结果...");
//        Integer result = future.get();
//        log.debug("结果是: {}", result);
        
        // 使用异步方式GenericFutureListener接口
        future.addListener(future1 -> log.debug("接收结果: {}", future1.getNow()));
    }
    
    

}
